<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
  <head>
    <title>process-rule-update</title>
   
	<%@ include file="../include/common.jsp"%>
	<%@ include file="../include/jbox.jsp"%>
    <%@ include file="../include/form.jsp"%>
    <%@ include file="../include/table.jsp"%>
    <link href="${pageContext.request.contextPath}/style/default/form/ui.tabs.css" type="text/css" rel="stylesheet" media="print, projection, screen"/>
    <script type="text/javascript" src="${pageContext.request.contextPath}/js/form/ui.tabs.js"></script>
	 <link rel="stylesheet" media="all" type="text/css" href="${pageContext.request.contextPath}/style/default/tree/zTreeStyle.css" />
	<style type="text/css">
		.ztree {border: 1px solid #617775;background: #f0f6e4;width:220px;height:360px;overflow-y:scroll;overflow-x:auto;}
	</style>
	<script type="text/javascript" src="${pageContext.request.contextPath}/js/tree/jquery.ztree.all-3.1.min.js"></script>
	 
	<script src="${pageContext.request.contextPath}/js/crontab/Simple_util.js"></script>
    <script src="${pageContext.request.contextPath}/js/TimeUnit/TimeUnit.js"></script>
    <script src="${pageContext.request.contextPath}/js/TimeUnit/TimeUnit_data_zh_CN.js"></script>
	
	<script type="text/javascript">
		function add(){
			//判断是否选择了资源
			if('${resId}' == ''){
				getTopWin(window).getMessageBox().alert("请先在左侧树选择资源","提示");
				return false;
			}
			var level = new Array();
			var j = 0;
			for(i = 1;i <= 5; i++){
				var str=document.getElementById("eventLevels"+i);
				if(str.checked == true){
					 level[j++] = str.value;
				}
			}
				//校验-事件级别
				if(level.length == 0){
					window.setTimeout(function () { $.jBox.tip('事件级别不能为空', 'success'); }, 100);
					return false;
				}	
			//提交
			 $.ajax({
				   type: "POST", 
				   url: "${pageContext.request.contextPath}/order/process-rule!save.action?eventLevel="+level, //请求的action
				   data: $("#myform").serialize(), //传的参数
				   dataType: 'json',
				   success: function(data){ //结果
				   		$("#id").val(data.workOrderId);
				   		window.setTimeout(function () { $.jBox.tip('基本信息保存成功', 'success'); }, 100);
				   }
			});
		  }
		  $(function(){
			  var array = '${eventTypeName}'.split(',');
				var str ='';
				for(var i = 0 ; i< array.length;i++){
					if(i == 10){
						str = str+'....';
					}
					str += array[i]+'</br>';
				}
				$("#views").html(str);
				
			  if('${radio}' == 'all'){
				  $("#radios1").attr("checked","checked");
			  }else{
				  $("#radios2").attr("checked","checked");
			  }
			  var eventLevels = '${workOrder.eventLevels}'.split(',');
			  for(var i= 0 ; i< eventLevels.length;i++){
				  if(eventLevels[i] == '2'){
					  var str=document.getElementById("eventLevels1");
						str.checked = 'checked';
				  }
					if(eventLevels[i] == '3'){
						 var str=document.getElementById("eventLevels2");
						 str.checked = 'checked';			  
									  }
					if(eventLevels[i] == '4'){
						 var str=document.getElementById("eventLevels3");
						 str.checked = 'checked';
					}
					if(eventLevels[i] == '5'){
						 var str=document.getElementById("eventLevels4");
						 str.checked = 'checked';
					}
					if(eventLevels[i] == '1'){
						 var str=document.getElementById("eventLevels5");
						 str.checked = 'checked';
					}
			  }
			  $.formValidator.initConfig({formid:"myform"
		          ,onerror:function(msg){}
		          ,onsuccess:function(){
		        	  		add();
		          			return false;
		          }
		      });
			  $("#name").formValidator({onshow:"请输入字符串 长度(1-128) 不能重复",onfocus:"请输入字符串  长度(1-128) 不能重复",oncorrect:"输入正确"}).inputValidator({min:1,onerror:"不能为空"})
			  .functionValidator({
				    fun:function(val,elem){
				    	    if(val.replace(/[^\x00-\xff]/g, "xx").length > 128){
				    	        return "长度超出最大范围";
				    	    }
				    	    return true;
					}
		  	  }).ajaxValidator({
					type : "post",
					async : false,
					url:'${pageContext.request.contextPath}/order/process-rule!checkName.action',
					data: "resId="+$("#resId").val()+"&name="+encodeURI(encodeURI($("#name").val()))+"&oldName="+encodeURI(encodeURI('${workOrder.name}')),
					datatype : "json",
					success : function(data){
						if(data== true)
						{
							return true;
						}else
						{
							return false;
						}
		   			},
				buttons: $("#button"),
				error: function(){alert("服务器没有返回数据，可能服务器忙，请重试");},
				onerror : "已经存在",
				onwait : "正在校验"
				});
			  $("#sendClass").formValidator({onshow:"请选择工单发送方式,不能为空",onfocus:"请下拉选择",oncorrect:"输入正确"}).inputValidator({min:0,onerror:"配置文件不正确，请查看"})
			  .functionValidator({
				  fun:function(val,elem){
			    	    if(val.length <1){
			    	        return "请查看配置文件是否正确";
			    	    }
			    	    return true;
				}
			  });
		  });
		  function closewin(){
			  window.history.back();
		  }
		  function pageReset(){
			  $("#myform").get()[0].reset(); 
			}
		  function showEventTypeTree(){
			  	var url ="iframe:notify/notify-rule!eventType.action?notifyRuleId="+$("#id").val()+"&eventType="+$("#eventTypeId").val();
				var opt = { title: "自定义事件类别",width:340,height:350,buttons: {}};
				getTopWin(window).openjBox(url,opt,'add-eventtype-rule',window);
				
			}
		
			 function clearEventType(){
				  $("#eventTypeId").val('');
				  $("#views").html('');
			  }
			function setEventTypeId(eventTypeId,eventTypeName){
				 $("#radios2").attr("checked","checked");
				$("#eventTypeId").val(eventTypeId);
				var array = eventTypeName.split(',');
				var str ='';
				for(var i = 0 ; i< array.length;i++){
					if(i == 10){
						str = str+'....';
					}
					str += array[i]+'</br>';
				}
				$("#views").html(str);
			}
			function show(){
				if($("#views").html() != ''){
					$("#views").css({"top":$("#show").offset().top+12+"px", "left":$("#show").offset().left+"px", "visibility":"visible"})
				}
			}
		  function closed(){
				$("#views").css({"visibility":"hidden"})
			}
		  
		  
		  function datagridResExclude(){
				var oTable=	$('#depmtList').dataTable();
				 oTable._fnAjaxUpdate();
			}
			$(function(){
				//加载grid
				var oTable=	$('#depmtList').dataTable({
					"bProcessing": false, 
					"bServerSide": true,
					"sServerMethod": 'POST',
					"sAjaxSource":'${pageContext.request.contextPath}/order/process-rule!listResExclude.action?resId='+$("#id").val(),
					"bPaginate": false,
					"bSort": true,
					"bFilter":false,
					"bJQueryUI":false,
					"fnServerParams":function(aoData){aoData.push({'name':'workOrderId','value':$("#id").val()});},
					"aoColumns":[
						{"mDataProp":"op","":"center","bSortable": false},
						{"mDataProp":"data","bSortable": false},
						{"mDataProp":"id","bVisible":false}
					], 
					 "oLanguage": { 
						 "sZeroRecords": "没有找到记录",
							"sInfo":" ",
							"sInfoEmpty": " "
					}
				});
			});	

			function addResExclude() {
				if($("#id").val() == ''){
					getTopWin(window).getMessageBox().alert("请先保存基本信息","提示");
				}else{
					var url ="iframe:order/process-rule!addResExclude.action?workOrderId="+$("#id").val()+"&resId="+$("#resId").val();
					var opt = { title: "新增子资源过滤",width:345,height:358,buttons: {}};
					getTopWin(window).openjBox(url,opt,'add-exclude-rule',window);
				}
			}
			function delResExclude(id){
				var submit = function (v, h, f) {
				    if (v == 'ok') {
				    	$.ajax({
				    		type : "POST",
				    		url : "${pageContext.request.contextPath}/order/process-rule!delResExclude.action?id="+id, //请求的action
				    		data : '', //传的参数
				    		dataType : 'json',
				    		success : function(data) { //结果
				    			window.setTimeout(function () { $.jBox.tip('删除成功。', 'success'); }, 100);
				    			datagridResExclude();
				    		}
				    	});
				    }
				    else if (v == 'cancel') {
				    }
				    return true; //close
				};
				getTopWin(window).jBox.confirm("确定要删除数据吗？", "提示", submit);
			}
	</script>

  </head>
  
  <body>
  
  		<h2 class="title-h2"><span>流程工单基本信息</span></h2>
   		<div id="menuContent" style="display:none; position: absolute;z-index:100;">
			<ul id="treeDemo" class="ztree" style="margin-top:0; width:200px; height: 200px;"></ul>
		</div>
   		<div>
				<form action="" id="myform" name="myform" method="post">
				<div id="views" style="position:absolute; visibility:hidden;border:2px solid #CCC;background-color:white;">
				</div>
					<table class="table_eidt">
			  			<tr style="height:40px">
				    		<td class="td_left" width="120px">
								资源名称
				    		</td>
				    		<td class="td_right">
				    			${resName}
				    			<input type="hidden" id="resId" name="resId" value='${resId}'>
				    		</td>
			    		</tr>
			    		<tr style="height:40px">
				    		<td class="td_left">
								<span class="span_alert">*</span>事件级别
				    		</td>
				    		<td class="td_right" style="line-height:16px;">
				    		  <input style="float:left;" type="checkbox" name="eventLevels" id="eventLevels1"  value="2"><font style="line-height:20px; float:left; display:block; width:40px; height:20px;" color='#C8FF00'>轻微</font>
					          <input style="float:left;" type="checkbox" name="eventLevels" id="eventLevels2" value="3" ><font style="line-height:20px; float:left; display:block; width:40px; height:20px;" color='#FFD200'>警告</font>
					          <input style="float:left;" type="checkbox" name="eventLevels" id="eventLevels3" value="4"><font style="line-height:20px; float:left; display:block; width:40px; height:20px;" color='#FF9200'>重要</font>
					          <input style="float:left;" type="checkbox" name="eventLevels" id="eventLevels4" value="5" ><font style="line-height:20px; float:left; display:block; width:40px; height:20px;" color='#FF1042'>严重</font>
					          <input style="float:left;" type="checkbox" name="eventLevels" id="eventLevels5" value="1"><font style="line-height:20px; float:left; display:block; width:40px; height:20px;" color='black'>恢复</font>
				    		  <span id="eventLevelsTip" style="width:150px"></span>
				    		</td>
			    		</tr>
			    		<tr style="height:40px">
				    		<td class="td_left">
								<span class="span_alert">*</span>工单名称
				    		</td>
				    		<td class="td_right">
				    			<input type="text" id="name" name="name" style="width: 200px;" value=${workOrder.name}>
				    			<span id="nameTip" style="width:150px"></span>
				    		</td>
			    		</tr>
			    		<tr style="height:40px">
				    		<td class="td_left">
								<span class="span_alert">*</span>发送方式
				    		</td>
				    		<td class="td_right">
				    			<select id="sendClass" name="sendClass">
				    				<%List<String> names = (List<String>)request.getAttribute("classNames"); 
				    					if(names!=null&&names.size()>0){
				    						for(String name:names){
				    				%>
				    				<option><%=name %></option>
				    				<%} }%>
				    			</select>
				    			<span id="sendClassTip" style="width:150px"></span>
				    		</td>
			    		</tr>
			    		<tr style="height:40px">
				    		<td class="td_left">
								事件类别
				    		</td>
				    		<td class="td_right">
				    			<input type="radio" name="radios" id="radios1" checked="checked" onclick="clearEventType();">全部&nbsp;&nbsp;
    							<input name="radios" id="radios2" type="radio" onclick="showEventTypeTree();"><span onmouseover="show();" onmouseout="closed();" id="show" onclick="showEventTypeTree();" style="color: blue;"><a>自定义</a></span>
				    			<input type="hidden" id="eventTypeId" name="eventTypeId" value='${eventType}'>
				    		</td>
			    		</tr>
			  		</table>
			  		<div style="margin-left:150px; margin-top:5px;">
				    	<input type="submit" id="button" name="button" value="保存" class="btn-4">
				    	<input type="button" value="重置" class="btn-4" onclick="pageReset();">
				    	<input type="button" value="返回" onclick="closewin();" class="btn-4">
		    		</div>
		    		<input id="id" name="id" type="hidden" value=${workOrder.id}>
				</form>
		</div>
		<h2 class="title-h2"><span>子资源过滤</span></h2>
		<div>
		<div class="toolbar" id = "toolbar">
			<a class="page_add" href="javascript:addResExclude();">新增</a>
		</div>
		<table id="depmtList" width="100%" cellpadding="0" cellspacing="0"
			border="0" class="display" title="查询结果">
			<thead>
				<tr>
					<th width="2%">操作</th>
					<th width="45%">被排除的子资源</th>
				</tr>
			</thead>
		</table>
	</div>
    </body>
</html>
